home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 15 / BBS in a box XV-1.iso / Files / Educ / Calc / MathPad 2.35.sit / Examples / Poisson / Poisson
Encoding:
Text File  |  1995-04-29  |  782 b   |  32 lines  |  [TEXT/MPad]

  1. -- Generate Poisson random inter-event times.
  2. -- Since the Poisson distribution is a simple exponential, the inverse of its integral can be used to transform the uniform random distribution.
  3.  
  4. poissonrand(aveper) = -ln(rand(1))*aveper
  5.  
  6. -- Check the distribution by accumulating a histogram.
  7. include ":incl:histogram"
  8.  
  9. -- make an array of random inter-event times
  10. nevents = 600
  11. aveper = 2.5
  12. dt[i] = poissonrand(aveper) dim[nevents]
  13.  
  14. -- accumulate a histogram of number of events vs. inter-event time.
  15. nbins = 40
  16. histo(dt,Xmin,Xmax,nbins):
  17. total:593.000
  18.  
  19. plot bins
  20. label mean:2.389
  21. label aveper:2.500
  22. Xmin=0; Xmax=5*aveper
  23. Ymin=0;
  24.  
  25. -- plot the continuous Poisson distribution
  26. poisson(t) = exp(-t/aveper)
  27.  
  28. plot bin1*poisson(X)
  29.  
  30. bint = (Xmax-Xmin)/nbins
  31. bin1 = nevents*(1-poisson(bint))
  32.